package  com.sat.common.utils

import java.text.SimpleDateFormat
import java.util.*

object  DateUtil {
    /**
     * 一小时的秒数
     */
    private val HOUR_SECOND = 60 * 60

    /**
     * 一分钟的秒数
     */
    private val MINUTE_SECOND = 60

    /**
     * 根据秒数获取时间串
     *
     * @param second (eg: 100s)
     * @return (eg : 00 : 01 : 40)
     */
    fun getTimeStrBySecond(second: Int): String? {
        var second = second
        if (second <= 0) {
            return "00:00:00"
        }
        val sb = StringBuilder()
        val hours = second / HOUR_SECOND
        if (hours > 0) {
            second -= hours * HOUR_SECOND
        }
        val minutes = second / MINUTE_SECOND
        if (minutes > 0) {
            second -= minutes * MINUTE_SECOND
        }
        return if (hours >= 10) hours.toString() + "" else "0$hours" + ":" + (if (minutes >= 10) minutes.toString() + "" else "0$minutes") + ":"+ if (second >= 10) second.toString() + "" else "0$second"
    }

    /**
     * 根据秒数获取时间串
     *
     * @param second (eg: 100s)
     * @return (eg : 01 : 40)
     */
    fun getMinAndSecondBySecond(second: Int): String? {
        var second = second
        if (second <= 0) {
            return "00:00"
        }
        val sb = StringBuilder()
        val minutes = second / MINUTE_SECOND
        if (minutes > 0) {
            second -= minutes * MINUTE_SECOND
        }
        return ((if (minutes >= 10) minutes.toString() + "" else "0$minutes") + ":"
                + if (second >= 10) second.toString() + "" else "0$second")
    }

    /**
     * java 获取 获取某年某月 所有日期（yyyymmdd格式字符串）
     *
     * @return
     * @
     */
    fun getMonthFullDay(): String? {
        val dateFormatYYYYMMDD = SimpleDateFormat("yyyyMMdd")
        val calendar = Calendar.getInstance()
        return dateFormatYYYYMMDD.format(calendar.time)
    }

}